package com.longcai.controller.customer;


import com.alibaba.fastjson.JSONObject;
import com.longcai.advice.RollBackExecption;
import com.longcai.bean.ApiResult;
import com.longcai.constants.BaseConstants;
import com.longcai.entity.customer.ClyjUser;
import com.longcai.entity.customer.ClyjUserProperty;
import com.longcai.service.customer.ClyjUserPropertyService;
import com.longcai.util.TokenUtils;
import com.longcai.vo.ClyjGoodsOrderDetailsVo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.math.BigDecimal;

/**
 * <p>
 * 用户资产表 前端控制器
 * </p>
 *
 * @author M
 * @since 2019-03-21
 */
@Controller
@RequestMapping("/clyjUserProperty")
public class ClyjUserPropertyController {

    @Autowired
    private ClyjUserPropertyService clyjUserPropertyService;
    @Autowired
    private TokenUtils tokenUtils;

    /**
     * 查询用户资产
     *
     * @return ：用户资产表
     */
    @RequestMapping("/queryUserProperty")
    public ApiResult<?> queryUserProperty(@RequestBody JSONObject params) {
        String token = params.getString("token");
        if (token == null || "".equals(token)) {
            return ApiResult.fail("您好，你的账号已登陆失效，请重新登陆！");
        }
        ClyjUser clyjUser = tokenUtils.Itoken(token);
        if (clyjUser == null) {
            return ApiResult.fail("您好，你的账号已登陆失效，请重新登陆！");
        }
        ClyjUserProperty c = clyjUserPropertyService.queryUserProperty(clyjUser.getUserId());
        return ApiResult.success(c);
    }

    /**
     * 资产变动
     *
     * @return ：资产变动
     * @throws RollBackExecption 
     */
    @RequestMapping("/changeFinance")
    public ApiResult<?> changeFinance(@RequestBody JSONObject params) throws RollBackExecption {
        String token = params.getString("token");
        if (token == null || "".equals(token)) {
            return ApiResult.fail("您好，你的账号已登陆失效，请重新登陆！");
        }
        ClyjUser clyjUser = tokenUtils.Itoken(token);
        if (clyjUser == null) {
            return ApiResult.fail("您好，你的账号已登陆失效，请重新登陆！");
        }
        ApiResult<?> r = clyjUserPropertyService.changeFinance(clyjUser.getUserId(), new BigDecimal(1), BaseConstants.PAY_CODE, "zhuce", "0", null, BaseConstants.UNFREEZE,null);
        return r;
    }
    
    /**
     * 解冻
     *
     * @return ：解冻
     */
    @RequestMapping("/thaw")
    public ApiResult<?> thaw(@RequestBody ClyjGoodsOrderDetailsVo clyjGoodsOrderDetailsVo) {
        String token = clyjGoodsOrderDetailsVo.getToken();
        if (token == null || "".equals(token)) {
            return ApiResult.fail("您好，你的账号已登陆失效，请重新登陆！");
        }
        ClyjUser clyjUser = tokenUtils.Itoken(token);
        if (clyjUser == null) {
            return ApiResult.fail("您好，你的账号已登陆失效，请重新登陆！");
        }
        ApiResult<?> r = clyjUserPropertyService.thaw(clyjGoodsOrderDetailsVo);
        return r;
    }

}